package delta;

public class Elf extends Enemy {

	public Elf(Road road) {
		road.addObject(this);
		currentRoad = road;
		prewiousRoad=null;
		life = 150;
		speed = 0;
		steps = 100;
	}

	public Elf(Integer clife, Integer cspeed, Integer csteps, Road croad) {
		life = clife;
		speed = cspeed;
		steps = csteps;
		croad.addObject(this);
		currentRoad = croad;
	}

	public boolean action(ActionParameters ap) {
		if(ap==null)return true;
		if(ap.getDamageDE()!=null)life = life - ap.getDamageDE();
		if(ap.getSpeed()!=null)speed = ap.getSpeed();
		if (life <= 0) {
			Player.increaseWitchcraft(100);
			currentRoad.removeObject(this);
			//View miatt
			currentRoad=null;
		}
		if (ap.isCutter()) {
			life = life / 2;
			new Elf(life, speed, steps, currentRoad);
		}
		return true;
	}

	public void update() {
		steps = steps - ((23 - speed * 2) / 2);
		if (steps < 0) {
			steps = 100 + steps;
			currentRoad.removeObject(this);
			Road temp=currentRoad;
			currentRoad = currentRoad.getNextRandomRoad();
			
			while(currentRoad==prewiousRoad){
				
				currentRoad = temp.getNextRandomRoad();
			}
			
			if (currentRoad == null) {
				Player.setIsEndOfWorld(true);
			} else {
				prewiousRoad=temp;
				currentRoad.addObject(this);
				speed = 0;
			}
		}
	}

	public String toString() {
		StringBuilder str = new StringBuilder();
		str.append("Elf:\n");
		str.append("Life= " + life + "\n");
		str.append("Speed= " + speed + "\n");
		str.append("Steps= " + steps + "\n\n");
		return str.toString();
	}

	@Override
	public String getMapchar() {
		// TODO Auto-generated method stub
		return new String("E");
	}

	public Field getField() {
		// TODO Auto-generated method stub
		return currentRoad;
	}

}